<template>
  <div class="dashboard-container">
    <aside class="aside-style">
      <el-row>
        <el-col :span="4">
          <el-input v-model="keyword" clearable placeholder="请输入搜索的关键字">
            <el-button slot="append" icon="el-icon-search" @click="searchFun" />
          </el-input>
        </el-col>
      </el-row>
    </aside>
    <el-table
      :data="tableData"
      style="width: 100%;margin-top: 20px;font-size:12px;"
      row-key="id"
      border
      :default-expand-all="false"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column
        prop="title"
        label="标题"
      />
      <el-table-column
        label="类别"
      >
        <template slot-scope="scope">
          {{ scope.row.type === '1' ? '分类' : '规章制度' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="datetime"
        label="发布时间"
      />
      <el-table-column>
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="checkInfo(scope.row)">查看</el-button>
          <delConfirm :title="`是否确认删除【${scope.row.title}】规章制度？`" @onConfirm="delFun(scope.row)" />
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
import delConfirm from '@/components/DelConfirm'
import { getRulesListApi, deleteRulesInfoApi } from '@/api/main'
export default {
  components: {
    delConfirm
  },
  data() {
    return {
      keyword: '',
      tableData: []
    }
  },
  created() {
    this.getRulesList()
  },
  methods: {
    delFun(row) {
      console.log(row)
      const data = {
        id: row.id
      }
      deleteRulesInfoApi(data).then(res => {
        if (res.code === 200) {
          this.$message.success(res.msg)
          this.getRulesList()
        } else if (res.code === 400) {
          this.$message.error(res.msg)
        }
      })
    },
    searchFun() {
      console.log(this.keyword)
      this.getRulesList()
    },
    checkInfo(row) {
      this.$router.push({
        name: 'rules-info-reset',
        params: { id: row.id }
      })
    },
    getRulesList() {
      const data = {
        keyword: this.keyword
      }
      getRulesListApi(data).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.tableData = res.list
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
    &-container {
        margin: 30px;
    }
    &-text {
        font-size: 30px;
        line-height: 46px;
    }
}
</style>
